﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EDiamondModel;

public partial class Admin_Test : System.Web.UI.Page
{
    EDiamondEntities1 db = new EDiamondEntities1();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int khoa = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        try
        {
            KhachHang entity = db.KhachHangs.Include("DatHangs").SingleOrDefault(p => p.KhachHangID == khoa);

            if (entity.DatHangs.Count > 0)
            {
                throw new Exception("Không hủy được ");

            }
            db.KhachHangs.DeleteObject(entity);
            db.SaveChanges();
            throw new Exception("hủy được ");

        }
        catch (Exception ex)
        {
            throw new Exception("Không hủy được ");
        }
    }
}